package com.victualler.core.config.img.service.impl;

import com.victualler.core.base.service.impl.BaseServiceImpl;
import com.victualler.core.config.img.entity.ImageDirDao;
import com.victualler.core.config.img.entity.ImageItemDao;
import com.victualler.core.config.img.repository.ImageDirRepository;
import com.victualler.core.config.img.repository.ImageItemRepository;
import com.victualler.core.config.img.repository.impl.ImageDirQueryRepositoryImpl;
import com.victualler.core.config.img.service.ImageDirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Guoshichang
 * @Date: Create in 23:00 2018-04-23
 * @Discription:
 */
@Service
public class ImageDirServiceImpl  extends BaseServiceImpl<ImageDirDao,ImageDirRepository,ImageDirQueryRepositoryImpl> implements ImageDirService {
    @Autowired
    private ImageItemRepository imageItemRepository;

    @Override
    public List<ImageDirDao> getByParentId(Long parentId) {
        return this.baseRepository.findByParentId(parentId);
    }

    @Override
    public boolean dirIsUsed(Long id) {
        List<ImageItemDao> result = this.imageItemRepository.findByImageDirId(id);
        List<ImageDirDao> dirList = this.getByParentId(id);
        if((result ==null || result.size() == 0) && dirList.size() == 0){
            return false;
        }
        return true;
    }


}
